package com.base.sampleproject;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.InputType;
import android.util.Log;
import android.view.View;

import com.devnn.base.BaseActivity;
import com.devnn.baseNet.BaseDAO;
import com.devnn.util.BaseUtil;
import com.devnn.view.ConfirmDialog;
import com.devnn.view.InputDialog;
import com.sample.dao.TestDAO;

import java.util.HashMap;
import java.util.Map;

public class SampleActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener {
    private SwipeRefreshLayout refreshLayout;
    private TestDAO testDAO;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_sample);
        super.onCreate(savedInstanceState);
        int density_dpi = this.getResources().getDisplayMetrics().densityDpi;
        float density = this.getResources().getDisplayMetrics().density;
        Log.i(TAG, "density_dpi:" + density_dpi);
        Log.i(TAG, "density:" + density);
    }

    public void play(View view) {
        showInfoDialog("找不到音效文件");
//        AudioManager audioManager= (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
//        int curVolume=audioManager.getStreamVolume(AudioManager.STREAM_RING);
//        int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
//        audioManager.setStreamVolume(AudioManager.STREAM_RING, maxVolume, 0);
//        BaseUtil.playVoice(this, R.raw.new_order);
//        audioManager.setStreamVolume(AudioManager.STREAM_RING, curVolume, 0);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }

    @Override
    protected void init() {
        // TODO Auto-generated method stub
        refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
        refreshLayout.setOnRefreshListener(this);
        refreshLayout.setColorSchemeResources(R.color.color_orange, R.color.color_green);
//        refreshLayout.setRefreshing(true);
    }

    @Override
    protected void setData() {
        // TODO Auto-generated method stub

    }

    public void load(View view) {
        super.showLoadDialog("请稍候");
    }

    public void ask(View view) {
        super.showConfirmDialog("确实要删除吗?", new ConfirmDialog.OnSelectedListener() {
            @Override
            public void onSureSelected() {
                BaseUtil.showTextToast(SampleActivity.this, "删除成功");
            }

            @Override
            public void onCancelSelected() {
                BaseUtil.showTextToast(SampleActivity.this, "取消");
            }
        });
    }

    public void input(View view) {
        super.showInputDialog("请输入IP地址", InputType.TYPE_NUMBER_FLAG_DECIMAL, new InputDialog.OnInputSureListener() {
            @Override
            public void onInputSure(String text) {
                BaseUtil.showTextToast(SampleActivity.this, text);
            }

            @Override
            public void onInputCancel() {

            }
        });
    }

    public void takePhoto(View view) {
        Intent intent = new Intent();
        intent.setAction(MediaStore.Audio.Media.ALBUM);

    }

    public void choice(View view) {
        final String[] array = this.getResources().getStringArray(R.array.array_condition);
        AlertDialog dialog = new AlertDialog.Builder(this).setItems(array, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                BaseUtil.showTextToast(SampleActivity.this, array[which]);
            }
        }).create();
        dialog.show();
    }

    public void testNet(View view) {
        testDAO = new TestDAO();
        Map<String, Object> params = new HashMap<>();
        params.put("courierId", 3049);
        params.put("orderStatus", 1);
        params.put("baseOrderId", "");
        testDAO.setRequestListener(this);
        testDAO.request(params);
        super.showLoadDialog("请稍候...");
    }

    public void draw(View view) {
        Intent intent = new Intent(this, DrawActivity.class);
        startActivity(intent);

    }

    public void lukyDraw(View view) {
        Intent intent = new Intent(this, LukyDrawActivity.class);
        startActivity(intent);
    }

    public void newlukyDraw(View view) {
        Intent intent = new Intent(this, NewLukyDrawActivity.class);
        startActivity(intent);
    }

    public void circlelukyDraw(View view) {
        Intent intent = new Intent(this, CircleLukyActivity.class);
        startActivity(intent);
    }

    @Override
    public void onRefresh() {
        Log.i(TAG, "正在刷新...");
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                // TODO Auto-generated method stub
                BaseUtil.showTextToast(SampleActivity.this, "刷新完成");
                refreshLayout.setRefreshing(false);
            }
        }, 1000);

    }

    @Override
    public void onRequestSucceed(BaseDAO baseDAO) {
        super.onRequestSucceed(baseDAO);
        super.showInfoDialog("请求成功");
    }

    @Override
    public void onRequestFailed(BaseDAO baseDAO) {
        super.onRequestFailed(baseDAO);
    }
}
